﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;

namespace EasyFramework.Web.PageSubmit
{
    /// <summary>
    /// 方法总结：http://www.cnblogs.com/blsong/archive/2009/12/24/1631144.html
    /// </summary>
    public partial class 防止页面重复提交 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("if (typeof(Page_ClientValidate) == 'function') { if (Page_ClientValidate() == false) { return false; }}");//保证验证函数的执行
            sb.Append("if(window.confirm('提醒：您确定要进行此次操作吗？')==false) return false;");//自定义客户端脚本
            sb.Append("disableOtherSubmit();");// disable所有submit按钮
            sb.Append(ClientScript.GetPostBackEventReference(this.btnSubmit, null));//用__doPostBack来提交，保证按钮的服务器端click事件执行
            sb.Append(";");
            btnSubmit.Attributes.Add("onclick", sb.ToString());
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Thread.Sleep(3000);
            Response.Write("12121212");
        }
    }
}